package cn.rubbit.entity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Table extends BaseBean {
	private String table;
	private List<Entity> entities;
	private String schema;
	private String pk;
	private String packageName;

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		StringBuffer sb = new StringBuffer();
		sb.append(table.substring(0, 1).toUpperCase()).append(table.substring(1));
		this.table = sb.toString();
	}

	public List<Entity> getEntities() {
		return entities;
	}

	public void setEntities(List<Entity> entities) {
		this.entities = entities;
	}

	public String getSchema() {
		return schema;
	}

	public void setSchema(String schema) {
		this.schema = schema;
	}

	public String getPk() {
		return pk;
	}

	public void setPk(String pk) {
		this.pk = pk;
	}

	@Override
	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("table", getTable());
		map.put("schema", getSchema());
		map.put("pk", getPk());
		map.put("packageName", getPackageName());
		Map<String, Object>[] deps = null;
		if (this.entities != null && this.entities.size() > 0) {
			deps = new Map[entities.size()];
			for (int i = 0; i < entities.size(); i++) {
				deps[i] = entities.get(i).toMap();
			}
		}
		map.put("entities", deps);
		return map;
	}

}
